From 61ff153ef515c6185010a9da550eaddad391d6b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Fri, 9 Sep 2005 11:07:52 +0000 Subject: [PATCH] more concise automatic names for formats --- ChangeLog | 9 ++ babl/babl-format.c | 41 ++++++- babl/base/model-lab.c | 229 ---------------------------------------- babl/base/model-rgb.c | 4 - babl/base/model-ycbcr.c | 17 +++ 5 files changed, 66 insertions(+), 234 deletions(-) delete mode 100644 babl/base/model-lab.c diff --git a/ChangeLog b/ChangeLog index 064f3b0..d6aa9ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-09-09 Øyvind Kolås + + * babl/babl-format.c: (create_name): Create shorter names when + the format uses a single datatype and the components are listed in + model order. + * babl/base/model-lab.c: removed. + * babl/base/model-rgb.c: (formats), + * babl/base/model-ycbcr.c: (formats): Use automatic names for formats. + 2005-09-09 Øyvind Kolås * babl/babl-classes.h: added error to BablConversion. diff --git a/babl/babl-format.c b/babl/babl-format.c index 606105f..56ad171 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -115,11 +115,50 @@ create_name (BablModel *model, BablType **type) { char *p = &buf[0]; + int i; + int same_types=1; + BablType **t=type; + BablType *first_type = *type; + BablComponent **c1=component; + BablComponent **c2=model->component; + sprintf (p, "%s ", model->instance.name); p+=strlen (model->instance.name) + 1; - while (components--) + i=components; + while (i--) + { + if (first_type != *t) + { + same_types=0; + break; + } + t++; + } + + i=components; + while (i--) + { + if (*c1 != *c2) + { + same_types=0; + break; + } + c1++; + c2++; + } + + + if (same_types) + { + sprintf (p, "%s", first_type->instance.name); + return buf; + } + + i=components; + + while (i--) { sprintf (p, "(%s as %s) ", (*component)->instance.name, diff --git a/babl/base/model-lab.c b/babl/base/model-lab.c deleted file mode 100644 index 5bebf13..0000000 --- a/babl/base/model-lab.c +++ /dev/null @@ -1,229 +0,0 @@ -/* babl - dynamically extendable universal pixel conversion library. - * Copyright (C) 2005, Øyvind Kolås. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include -#include "babl.h" -#include "util.h" -#include "cpercep.h" - -static void components (void); -static void models (void); -static void conversions (void); -static void formats (void); - -void -babl_base_model_lab (void) -{ - cpercep_init (); - components (); - models (); - conversions (); - formats (); -} - -static void -components (void) -{ - babl_component_new ( - "CIE L", - "id", BABL_CIE_L, - NULL); - - babl_component_new ( - "CIE a", - "id", BABL_CIE_A, - "chroma", - NULL); - - babl_component_new ( - "CIE b", - "id", BABL_CIE_B, - "chroma", - NULL); -} - -static void -models (void) -{ - babl_model_new ( - "CIE Lab", - "id", BABL_CIE_LAB, - babl_component_id (BABL_CIE_L), - babl_component_id (BABL_CIE_A), - babl_component_id (BABL_CIE_B), - NULL); - - babl_model_new ( - "CIE Lab alpha", - "id", BABL_CIE_LAB_ALPHA, - babl_component_id (BABL_CIE_L), - babl_component_id (BABL_CIE_A), - babl_component_id (BABL_CIE_B), - babl_component_id (BABL_ALPHA), - NULL); -} - -static void -rgb_to_lab (int src_bands, - void **src, - int *src_pitch, - int dst_bands, - void **dst, - int *dst_pitch, - int n) -{ - BABL_PLANAR_SANITY - - while (n--) - { - double red = *(double*)src[0]; - double green = *(double*)src[1]; - double blue = *(double*)src[2]; - - double L, a, b; - - cpercep_rgb_to_space (red, green, blue, &L, &a, &b); - - *(double*)dst[0] = L; - *(double*)dst[1] = a; - *(double*)dst[2] = b; - - if (dst_bands > 3) /* alpha passthorugh */ - *(double*)dst[3] = (src_bands>3)?*(double*)src[3]:1.0; - - BABL_PLANAR_STEP - } -} - -static void -lab_to_rgb (int src_bands, - void **src, - int *src_pitch, - int dst_bands, - void **dst, - int *dst_pitch, - int n) -{ - BABL_PLANAR_SANITY - - while (n--) - { - double L = *(double*)src[0]; - double a = *(double*)src[1]; - double b = *(double*)src[2]; - - double red, green, blue; - - cpercep_space_to_rgb (L, a, b, &red, &green, &blue); - - *(double*)dst[0] = red; - *(double*)dst[1] = green; - *(double*)dst[2] = blue; - - if (dst_bands > 3) /* alpha passthorugh */ - *(double*)dst[3] = (src_bands>3)?*(double*)src[3]:1.0; - - BABL_PLANAR_STEP - } -} - -static void -conversions (void) -{ - babl_conversion_new ( - "babl-base: rgba to cie-lab", - "source", babl_model_id (BABL_RGBA), - "destination", babl_model_id (BABL_CIE_LAB), - "planar", rgb_to_lab, - NULL - ); - babl_conversion_new ( - "babl-base: cie-lab to rgba", - "source", babl_model_id (BABL_CIE_LAB), - "destination", babl_model_id (BABL_RGBA), - "planar", lab_to_rgb, - NULL - ); - babl_conversion_new ( - "babl-base: rgb to cie-lab", - "source", babl_model_id (BABL_RGB), - "destination", babl_model_id (BABL_CIE_LAB), - "planar", rgb_to_lab, - NULL - ); - babl_conversion_new ( - "babl-base: cie-lab to rgb", - "source", babl_model_id (BABL_CIE_LAB), - "destination", babl_model_id (BABL_RGB), - "planar", lab_to_rgb, - NULL - ); - babl_conversion_new ( - "babl-base: rgba to cie-lab-float", - "source", babl_model_id (BABL_RGBA), - "destination", babl_model_id (BABL_CIE_LAB_ALPHA), - "planar", rgb_to_lab, - NULL - ); - babl_conversion_new ( - "babl-base: cie-lab-float to rgba", - "source", babl_model_id (BABL_CIE_LAB_ALPHA), - "destination", babl_model_id (BABL_RGBA), - "planar", lab_to_rgb, - NULL - ); -} - -static void -formats (void) -{ - babl_format_new ( - "cie-lab-float", - "id", BABL_LAB_FLOAT, - babl_model_id (BABL_CIE_LAB), - babl_type_id (BABL_FLOAT), - babl_component_id (BABL_CIE_L), - babl_component_id (BABL_CIE_A), - babl_component_id (BABL_CIE_B), - NULL); - - babl_format_new ( - "cie-lab-u8", - "id", BABL_LAB_U8, - babl_model_id (BABL_CIE_LAB), - babl_type_id (BABL_U8_CIE_L), - babl_component_id (BABL_CIE_L), - babl_type_id (BABL_U8_CIE_AB), - babl_component_id (BABL_CIE_A), - babl_type_id (BABL_U8_CIE_AB), - babl_component_id (BABL_CIE_B), - NULL); - - babl_format_new ( - "cie-lab-u16", - "id", BABL_LAB_U16, - babl_model_id (BABL_CIE_LAB), - babl_type_id (BABL_U16_CIE_L), - babl_component_id (BABL_CIE_L), - babl_type_id (BABL_U16_CIE_AB), - babl_component_id (BABL_CIE_A), - babl_type_id (BABL_U16_CIE_AB), - babl_component_id (BABL_CIE_B), - NULL); -} diff --git a/babl/base/model-rgb.c b/babl/base/model-rgb.c index 0bf9c06..73ecfe9 100644 --- a/babl/base/model-rgb.c +++ b/babl/base/model-rgb.c @@ -349,7 +349,6 @@ formats (void) NULL); babl_format_new ( - "name", "srgba", "id", BABL_SRGBA, babl_model_id (BABL_RGBA_GAMMA_2_2), babl_type_id (BABL_U8), @@ -360,7 +359,6 @@ formats (void) NULL); babl_format_new ( - "name", "rgba-float", "id", BABL_RGBA_FLOAT, babl_model_id (BABL_RGBA), babl_type_id (BABL_FLOAT), @@ -371,7 +369,6 @@ formats (void) NULL); babl_format_new ( - "name", "rgba-double", "id", BABL_RGBA_DOUBLE, babl_model_id (BABL_RGBA), babl_type_id (BABL_DOUBLE), @@ -382,7 +379,6 @@ formats (void) NULL); babl_format_new ( - "name", "rgb-float", "id", BABL_RGB_FLOAT, babl_model_id (BABL_RGB), babl_type_id (BABL_FLOAT), diff --git a/babl/base/model-ycbcr.c b/babl/base/model-ycbcr.c index f03cf76..6a3e2aa 100644 --- a/babl/base/model-ycbcr.c +++ b/babl/base/model-ycbcr.c @@ -196,6 +196,23 @@ conversions (void) static void formats (void) { + + babl_format_new ( + "name", "Y'CbCr u8 4:4:4", + "id", BABL_YCBCR420, + "planar", + babl_model_id (BABL_YCBCR), + babl_type_id (BABL_U8_LUMA), + babl_sampling (1, 1), + babl_component_id (BABL_LUMINANCE_GAMMA_2_2), + babl_type_id (BABL_U8_CHROMA), + babl_sampling (2, 2), + babl_component_id (BABL_CB), + babl_sampling (2, 2), + babl_component_id (BABL_CR), + NULL); + return; + babl_format_new ( "name", "y'cbcr420", "id", BABL_YCBCR420, -- 2.30.2